package kg.aibek.projecteuler.p10;

public class Problem35 {
	public void solve() {
		int count = 13;

		for (int i = 100; i < 1000000; i++) {
			if (isPrime(i) && isCircular(i)) {
				count++;
				System.out.println(i);
			}
		}

		System.out.println(count);
	}

	private boolean isCircular(int number) {
		String str = number + "";

		for (int i = 0; i < str.length(); i++) {
			str = str.substring(1) + str.charAt(0);
			int n = Integer.parseInt(str);
			if (!isPrime(n)) {
				return false;
			}
		}

		return true;
	}

	private boolean isPrime(int number) {
		for (int i = 2; i * i <= number; i++) {
			if (number % i == 0)
				return false;
		}
		return true;
	}

	public static void main(String[] args) {
		Problem35 p = new Problem35();
		p.solve();
	}
}
